package comparisons

import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"

// 比较float值
type FCMPG struct {
    base.NoOperandsInstruction
}

func (self *FCMPG) Execute(frame *rtda.Frame) {
    _fcmp(frame, true)
}

type FCMPL struct {
    base.NoOperandsInstruction
}

func (self *FCMPL) Execute(frame *rtda.Frame) {
    _fcmp(frame, false)
}

func _fcmp(frame *rtda.Frame, gFlag bool) {
    stack := frame.OperandStack()
    v2 := stack.PopFloat()
    v1 := stack.PopFloat()
    if v1 > v2 {
        stack.PushInt(1)
    } else if v1 == v2 {
        stack.PushInt(0)
    } else if v1 < v2 {
        stack.PushInt(-1)
    } else if gFlag {
        stack.PushInt(1)
    } else {
        stack.PushInt(-1)
    }
}
